package yin.com.controller.view;

import yin.com.controller.BaseServlet;
import yin.com.service.Userserver;
import yin.com.service.impl.Userserverimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/view/*")
public class Uiserver extends BaseServlet {
    private Userserver uiserver = new Userserverimpl();

    public void home(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        Object obj = req.getSession().getAttribute("userId");
        if (null != obj) {
            Integer userid = Integer.parseInt(obj.toString());
            Map<String, Object> map = uiserver.finduserByID(userid);
            req.setAttribute("userBasefo", map);

        }

        req.getRequestDispatcher("/html/home.jsp").forward(req, resp);


    }

    public void existence(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("/register.jsp").forward(req, resp);
    }

    public  void index(HttpServletRequest req, HttpServletResponse resp){
        try {
            req.getRequestDispatcher("/index.jsp").forward(req,resp);
        }catch (Exception e){
            e.printStackTrace();
        }

    }
    public  void forget(HttpServletRequest req, HttpServletResponse resp) {
        try {
            req.getRequestDispatcher("/forget.jsp").forward(req,resp);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


